<?php // cloud.php All Article Tags
require_once('./inc/inc.common.php');
$tmpl 			= new mvTemplate();

$tmpl->page_title('Keyword Cloud');

$sql = "SELECT * FROM (SELECT tag, COUNT(*) as cnt FROM tags GROUP BY tag ORDER BY COUNT(*) DESC) as toptag ORDER BY tag";
$query = $GLOBALS['db']->query($sql);
$tags = $query->fetchall();
$tagcount = $query->get_mysql_num_rows();

// min/max
$min = 0;
$max = 1;
foreach($tags as $v){
	if($v['cnt'] > $max)
		$max = $v['cnt'];
	if($v['cnt'] < $min || $min == 0)
		$min = $v['cnt'];
}

// set weight
foreach($tags as $k => $v){
	$tags[$k]['weight'] = round(($v['cnt'] - $min) / ($max - $min) * 9) + 1;
}

$tmpl->assign('tags', $tags);
$tmpl->assign('tag_count', $tagcount);

$tmpl->page_display('cloud.tpl');
?>